package aps

import glory.xxd.Utils

/**
 * 材料替换-扫设备请求物料信息
 */
class ShowMeterialController {
    def commentService
    /**
     * <EqpId>1FW0801</EQPID>
     <OPID>123</LOTID>
     <Materials></Materials>
     Meterial:
     1. ID ：物料唯一ID
     2. MaterialPartNo：物料产品编号
     3. Type ：物料类型
     4. Name ：物料名称
     5. OpName ：操作员
     6. EqpID ：设备ID
     7. LiftTime ：剩余寿命
     8. RemainTime ： 提醒日期
     9. StartTime ： 开始使用时间
     10. EndTime ： 结束时间时间
     11. Qty ：数量

     */
    def index() {

        def EqpId = params.EqpId
        def body = CommentParams.newInstance()
        body.setEqpId(EqpId)
        String logUUID =  Utils.getUUID();
        Header header = Header.newInstance()
        header.setMESSAGENAME("ShowMeterial");
        header.setTRANSACTIONID(logUUID);
        header.setUSERNAME("Client")
        //2018-03-06 测试json api 使用方法：getJsonByObjectForTopic2Queue_1
        //def json = commentService.getJsonByObjectForTopic2Queue(logUUID,header,body)
        def json = commentService.getJsonByObjectForTopic2Queue_1(logUUID,header,body)
        render  json
    }

    def testJson() {

        def r = Math.random()

        def xml = "<Response>\n" +
                "    <Header>\n" +
                "        <TRANSACTIONID>e58aaffc-619c-4eec-80c4-e20d1d64207a</TRANSACTIONID>\n" +
                "        <MESSAGENAME>SendEQPMeterial</MESSAGENAME>\n" +
                "        <USERNAME>EAP</USERNAME>\n" +
                "        <RESULT>SUCCESS</RESULT>\n" +
                "        <MESSAGEINFO>1FS216</MESSAGEINFO>\n" +
                "    </Header>\n" +
                "    <Body>\n" +
                "        <EqpId>1FS216</EqpId>\n" +
                "        <Materials>\n" +
                "            <MesMaterial>\n" +
                "                <id>0</id>\n" +
                "                <Type>HubBladeYZ1</Type>\n" +
                "                <EqpID>1FS216</EqpID>\n" +
                "                <Qty>0</Qty>\n" +
                "            </MesMaterial>\n" +
                "            <MesMaterial>\n" +
                "                <id>0</id>\n" +
                "                <Type>HubBladeYZ2</Type>\n" +
                "                <EqpID>1FS216</EqpID>\n" +
                "                <Qty>0</Qty>\n" +
                "            </MesMaterial>\n" +
                "        </Materials>\n" +
                "        <INPUTDATALIST />\n" +
                "    </Body>\n" +
                "</Response>";

        def json = Utils.getJsonObjectByXML_2(xml)
        def standardJSONForPDA = org.json.JSONObject.newInstance()

        standardJSONForPDA.put("data", json)
        standardJSONForPDA.put("code", 200)
        print standardJSONForPDA
        render standardJSONForPDA   
    }
}
